<template>
  <a-modal
    title="绩效信息"
    :width="800"
    :visible="visible"
    :confirmLoading="loading"
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }">
    <a-spin :spinning="loading">
      <a-form
        :form="form"
        v-bind="formLayout">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="绩效名称">
              <a-input

                placeholder="请输入绩效名称"
                v-decorator="['performanceName', { rules: [{ required: true, message: '请输入绩效名称' }] }]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="绩效类型">
              <a-select
                placeholder="请选择绩效类型"
                :disabled="true"
                v-decorator="['type', { rules: [{ required: true, message: '请输入绩效类型' }] }]">
                <a-select-option :value="1">项目绩效</a-select-option>
                <a-select-option :value="2">内部绩效</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="绩效分">
              <a-input
                placeholder="请输入绩效分"
                :disabled="isProjectPro"
                v-decorator="['performanceCategory', { rules: [{ required: true, message: '请输入绩效分' }] }]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="员工">
              <a-select
                placeholder="请选择员工"
                :disabled="isProjectPro"
                v-decorator="['userId', { rules: [{ required: true, message: '请选择员工' }] }]">
                <a-select-option
                  v-for="row in allUsers"
                  :key="row.userId"
                  :value="row.userId">{{ row.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col
            :span="12"
            v-if="isProjectPro">
            <a-form-item label="任务名称">
              <a-select
                placeholder="请选择任务"
                :disabled="isProjectPro"
                v-decorator="['taskId', { rules: [{ required: true, message: '请选择任务' }] }]">
                <a-select-option
                  v-for="row in []"
                  :key="row.taskId"
                  :value="row.taskId">{{ row.taskName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="依据">
              <a-input
                placeholder="请输入备注"
                v-decorator="['fact', { rules: [{ required: true, message: '请选择依据' }] }]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="备注">
              <a-input
                placeholder="请输入备注"
                v-decorator="['note']" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'

// 表单字段
const fields = ['id', 'brand', 'productName', 'note']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    allUsers: {
      type: Array,
      default: () => null
    },
    // tasks: {
    //   type: Array,
    //   default: () => null
    // },
    isProjectPro: {
      type: Boolean,
      default: () => false
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      form: this.$form.createForm(this)
    }
  },
  created () {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  }
}
</script>
